package com.qx.controller;

import com.qx.util.TencentYunVedioUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

import static com.qx.util.TencentYunVedioUtil.*;

@RestController
@RequestMapping("live")
public class LiveController {

    @PostMapping("createPushUrl")
    public static String createPushUrl() {
        //过期时间 16进制的unix时间戳
        String txTime = to16Hex(addOneDay());
        // 填写自己的streamName
        String streamName="123";
        StringBuffer sb = new StringBuffer();
        String pushUrlHead= PUSH_URL;
        // String stream_id = TencentYunVedioUtil.bizid();
        sb.append(pushUrlHead).append(streamName).append("?").append("txSecret=")
                .append(genSign(PUSH_KEY, streamName,txTime)).append("&").append("txTime=")
                .append(txTime);
        return sb.toString();
    }
    /**
     *      * 生成拉流全路径地址
     *      * @param playUrlHead  拉流的头地址
     *      * @param stream_id  直播码  调用该方法genLiveCode() 生成
     *      * @param play_key  拉流鉴权
     *      * @param end 如 .flv结尾
     *      * @return
     */
    @PostMapping("createPlayUrl")
    public static String createPlayUrl() {
        //过期时间 16进制的unix时间戳

        String txTime = to16Hex(addOneDay());
        StringBuffer sb = new StringBuffer();
        //String stream_id = TencentYunVedioUtil.bizid();
        sb.append(PLAY_URL_FLV).append("/123.m3u8").append("?").append("txSecret=").append(pushSign(PLAY_KEY, txTime))
                .append("&")
                .append("txTime=")
                .append(txTime);
        return sb.toString();
    }

}

